

// pages/my/myzixun/pj/pj.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    starRating:'',
    cid:'',
    content:'',
    consultant:'',
    conid:0,
    uid:0

  },

  rateStar(e){
    console.log(e);
    const index = e.currentTarget.dataset.index
    this.setData({
      starRating:index+1
    })
  },

  getConsultant(){
    wx.request({
      url: this.data.url+'consultantEvaluation/'+this.data.cid,
      success:res=>{
        this.setData({
          consultant:res.data.data.consultant,
          conid:res.data.data.consultant.id
        })               
      }
    })
    
  },

  insert(){

    wx.request({
      data:{
        content:this.data.content,
        star:this.data.starRating,
        consultantId:this.data.conid,
        evaluationTime:new Date,
      anonymity:this.data.anonymity,
      userId:this.data.uid,
      consultantId:this.data.conid,
      myConsultId:9
      },
      url: this.data.url+'consultantEvaluation',
      method:"POST"
      
    }),
    wx.showModal({
      title: '提交成功！！',
      content: '',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/my/myzixun/myzixun',
          })
        }
      }
    })

  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let user = wx.getStorageSync('user')
    this.setData({
      url:app.globalData.url,
      cid:options.id,
      uid:user.id
    })
    console.log(this.data.cid);

    this.getConsultant()
    
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})